<template>
    <!-- <h5>Custom colors</h5> -->
    <el-menu
        router
        v-model="isCollapse"
        active-text-color="#ffd04b"
        background-color="#545c64"
        class="el-menu-vertical-demo"
        :default-active="$route.path"
        text-color="#fff"
        @open="handleOpen"
        @close="handleClose"
        style="height: 100%;"
    >
        <el-sub-menu :index="item.index" v-for="(item,i) in subList">
            <template #title>
                <el-icon>
                    <icon-menu />
                </el-icon>
                <span>{{ item.name }}</span>
            </template>
            <el-menu-item
                v-for="(nav,i) in item.navList"
                :key="i"
                :index="nav.routerUrl"
            >{{ nav.routerName }}</el-menu-item>
        </el-sub-menu>
    </el-menu>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import {
    Menu as IconMenu,
} from '@element-plus/icons-vue'

export default defineComponent({
    components: {
        IconMenu
    },
    data() {
        return {
            subList: [
                {
                    name: '框图管理',
                    index: "1",
                    navList: [{

                        routerUrl: '/projectList',
                        routerName: '项目列表',
                    },
                    {
                        routerUrl: '/blockDiagramList',
                        routerName: '框图列表',
                    }]
                },
                {
                    name: '二级进度表管理',
                    index: "2",
                    navList: [{
                        routerUrl: '/addProgress',
                        routerName: '分部/分项名称维护',
                    }, {
                        routerUrl: '/scheduleTemplateMaintenanceList',
                        routerName: '进度模版维护列表',
                    },
                    // {
                    //     routerUrl: '/scheduleTemplateMaintenance',
                    //     routerName: '进度模版维护',
                    // }, 
                    // {
                    //     routerUrl: '/createSecondarySchedule',
                    //     routerName: '创建二级进度表',
                    // }, 
                    {
                        routerUrl: '/secondaryScheduleList',
                        routerName: '二级进度表列表',
                    }, {
                        routerUrl: '/jobList',
                        routerName: '任务列表',
                    }, {
                        routerUrl: '/secondarySchedule',
                        routerName: '进度一览表',
                    }]

                }]
        }
    },
    props: {
        menuval: String,
    },
    setup(props) {
        const selectMenuVal = props.menuval
        const isCollapse = ref(true)
        const handleOpen = (key, keyPath) => {
            console.log(key, keyPath)
        }
        const handleClose = (key, keyPath) => {
            console.log(key, keyPath)
        }
        return {
            selectMenuVal,
            isCollapse,
            handleOpen,
            handleClose,
        }
    },

    created() {
        const menuList = JSON.parse(sessionStorage.getItem('menuList'))
        const selectMenu = sessionStorage.getItem('selectMenu')
        menuList?.filter(menu => {
            if (menu.routerUrl === selectMenu) {
                // this.navList = menu.sidebarList
            }
        })
    },
})
</script>

<style>
.sidebar {
    width: 30%;
}
</style>
